<template>
  <!-- 新增 -->
  <el-dialog
    v-el-drag-dialog
    title="批量修改"
    :visible.sync="visible"
    width="500px"
    append-to-body
    @closed="reset"
  >
    <el-form v-if="visible" ref="dataForm" :model="form" label-position="right" label-width="110px">
      <el-form-item label="所属机构:" prop="orgId">
        <el-tree-select
          v-model="form.orgId"
          clearable
          class="tree-select"
          :popover-width="360"
          :select-params="{
            clearable: true,
            placeholder: '请选择',
          }"
          :tree-params=" {
            'expand-on-click-node': false,
            'highlight-current': true,
            'filterable': true,
            props:{
              value:'orgId',
              label: 'orgName',
              disabled: 'disabled',
            },
            data: treeData
          }"
        />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
      <el-button type="primary" :loading="$loadingPlugin.saveHandle" @click="saveHandle">
        保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { changeCsmOrg } from '@/api'
  export default {
    name: 'update-Org',
    props: {
      treeData: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        visible: false,
        form: {
          orgId: ''
        }
      }
    },
    methods: {
      open(data) {
        return new Promise(resolve => {
          this.resolve = resolve
          console.log(data)
          this.row = data
          this.visible = true
        })
      },
      async saveHandle() {
        if (!this.form.orgId) {
          this.$message.warning('所属机构不能为空！')
          return
        }
        const csmIdList = this.row.map((item) => (item.csmId))
        const param = {
          csmIds: csmIdList.join(','),
          newOrgId: this.form.orgId
        }
        const res = await changeCsmOrg(param)
        if (res) {
          this.$message.success('变更成功')
          this.resolve()
          this.reset()
          this.visible = false
        }
      },
      reset() {
        this.form = {
          orgId: ''
        }
        this.visible = false
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
